package com.rico.common.response;

import lombok.Data;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Calendar;

/**
 * @author 吴泽胜
 * @FileName RestResponse
 * @date 2021-04-23 10:21 上午
 * @Software: IntelliJ IDEA
 */

@Data
public class RestResponse<T> implements Serializable {

    private static final long serialVersionUID = 3728877563912075885L;

    // 状态码 0 -1
    private int code;
    // 信息
    private String msg;
    // 总数
    private Integer count;
    // 数据
    private T data;
    // 时间
    private String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime());

    public RestResponse(){}

    public RestResponse(int code, String message, T data) {
        this.code = code;
        this.setMsg(message);
        this.data = data;
    }

    public RestResponse(int code, String message, T data,Integer count) {
        this.code = code;
        this.setMsg(message);
        this.data = data;
        this.count = count;
    }

    public RestResponse(int code, T data) {
        this.code = code;
        this.data = data;
    }

    public RestResponse(int code, String message) {
        this.code = code;
        this.setMsg(message);
    }


    public int getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }


    public T getData() {
        return data;
    }

    public RestResponse setCode(int code) {
        this.code = code;
        return this;
    }

    public RestResponse setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    public RestResponse setData(T data) {
        this.data = data;
        return this;
    }

    @Override
    public String toString() {
        return "RestResponse{" + "code=" + code + ", msg='" + msg + '\'' +", data=" + data +'}';
    }


}

